package com.leaf.spring.y202002.day11.bio2;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.tomcat.util.threads.ThreadPoolExecutor;

/**
 * 增加线程池处理请求
 * 
 * @Title:
 * @Description:
 * @Author:leaf
 * @Since:2020年2月11日
 * @Version:1.1.0
 */
public class Server {

	public static void main(String[] args) {

		ExecutorService executor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), 50, 120, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));

		try (ServerSocket server = new ServerSocket(5678)) {

			// 进行阻塞
			Socket socket = null;

			while (true) {
				socket = server.accept();
				executor.execute(new ServerHandler(socket));
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
